

clear 
set scheme lean2, permanent
global pm = char(177)
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 

global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "experimentRNall.dta", clear

cd "$path_output"
 

 

loc experiments "unemp_prob z_unemp_cat unemp_county_prob z_fin_prosp earn_mean earn_sd jobinsecurity infl_mean infl_sd z_profits"

foreach var of varlist republican democrat finlit_index{
gen mis_`var' = `var'==.
replace `var'=0 if `var'==.
}

replace log_income=0 if inc_NR==1
global controls age agesq female log_income inc_NR atleast_bachelor midwest south west republican democrat finlit_index mis_republican mis_finlit_index

preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""

 


foreach choice in `experiments' {


***OLS


    qui reg `choice' posterior $controls , r
    sigstar posterior, prec(3)
    estadd loc thisstat4 = "`r(bstar)'": col`colnum'
    estadd loc thisstat5 = "`r(sestar)'": col`colnum'
	

	
***IV
	
    qui ivreg2 `choice' (posterior = treatment) $controls , r first
	mat firststage = e(first)
	mat r2=e(r2)
	sigstar posterior, prec(3)
    estadd loc thisstat10 = "`r(bstar)'": col`colnum'
    estadd loc thisstat11 = "`r(sestar)'": col`colnum'
	qui sum `choice'  
    estadd loc thisstat13 = r(N): col`colnum'	
	*estadd loc thisstat14 = string(r2[1,1], "%9.2f"): col`colnum'	
	estadd loc thisstat15 = string(r(mean), "%9.2f"): col`colnum'
	estadd loc thisstat16 = string(r(sd), "%9.2f"): col`colnum'	
	estadd loc thisstat17 = string(firststage[8,1], "%9.2f"): col`colnum'	
			
	loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

}
	
loc rowlabels " " " "{\bf Panel A: OLS}" " " "Posterior: Recession" " " " " "\hline" "{\bf Panel B: IV}" " " "Posterior: Recession" "  " " " "Observations" " " "Mean dep. var." "SD dep. var." "First stage F-stat" " "   "\hline" " "   "
loc rowstats ""

forval i = 1/17 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "table_mainresults.tex", replace cells(none) booktabs nonotes nomtitles /*nonum*/ compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
  mgroups("\shortstack{National\\unemployment\\(percent)}" "\shortstack{National\\unemployment\\(categorical)}" ///
  "\shortstack{County\\unemployment\\(percent)}" "\shortstack{Household\\financial\\prospects}" "\shortstack{Earnings\\growth:\\Mean}" ///
  "\shortstack{Earnings\\growth:\\Uncertainty}" "\shortstack{Personal\\unemployment\\(percent)}" "\shortstack{\\Inflation:\\mean}" "\shortstack{\\Inflation:\\Uncertainty}" "\shortstack{Firm\\profits\\(categorical)}", pattern(1 1 1 1 1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

	
	eststo clear	




















